package cn.com.controller;

import cn.com.mapper.MerchantMapper;
import cn.com.pojo.Menu;
import cn.com.pojo.Merchant;
import cn.com.pojo.User;
import cn.com.service.MenuService;
import cn.com.service.MerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class MerchantController {
    @Autowired
    MerchantService service;
    @PostMapping("/beComingMerchant")
    public String beComingMerchant(Merchant merchant, HttpSession session){
        User user= (User) session.getAttribute("USER");
        merchant.setUserName(user.getUname());
        merchant.setFlag("2");
        service.apply(merchant);
        return "index";
    }

    @Autowired
    MenuService menuService;
    @GetMapping("/addMenu")
    public String addMenu(Menu menu,HttpSession session){
        Merchant merchant= (Merchant) session.getAttribute("SHOP");
        menu.setMerchant_name(merchant.getUserName());
        menu.setShop_name(merchant.getShopName());
        System.out.println(menu);
        menuService.addMenu(menu);
        return "shop";
    }
}
